<template>
	<view>
		<view class="login">
			<input type="text" name="username" placeholder="请输入用户名" v-model="username">
			<input type="password" name="password" placeholder="请输入密码" v-model="password">
			<button size="mini" @click="login">登录</button>
		</view>
		<view class="register">
			<input type="text" placeholder="请输入用户名" v-model="registerName" />
			<input type="password" placeholder="请输入密码" v-model="registerPassword" />
			<button size="mini" @click="register">注册</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	const registerName = ref("")
	const registerPassword = ref("")
	const register = () => {
		uni.request({
			url: "http://47.94.6.186:3001/api/user/reg",
			method:"POST",
			data:{
				loginname:registerName.value,
				password:registerPassword.value
			},
			success:res=>{
				console.log(res.data);
			}
		})
	}

	const username = ref('')
	const password = ref('')
	const login = () => {
		uni.request({
			url: "http://47.94.6.186:3001/api/user/login",
			method: "POST",
			data: {
				loginname: username.value,
				password: password.value
			},
			success: res => {
				console.log(res.data);
				localStorage.setItem("token",res.data.data.token)
			}
		})
	}
</script>

<style>

</style>